﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CApCMCCreateContinuousMFGFromCurveCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CreateContinuousMFGFromCurve;

public class CApCMCCreateContinuousMFGFromCurveCmd : TxButtonCommand
{
  private CApCMCCreateContinuousMFGFromCurveEnabler _enabler;
  private const string _STRING_TABLE_LOCATION = "DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CMCStringTable";
  private ResourceManager _resourceManager;
  private TxForm _createContinousMFGFromCurveForm;
  private ITxObject _prevMfgContainer;
  private ITxObject _prevWeldOperation;

  public CApCMCCreateContinuousMFGFromCurveCmd()
  {
    this._enabler = new CApCMCCreateContinuousMFGFromCurveEnabler();
    this._resourceManager = new ResourceManager("DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CMCStringTable", ((object) this).GetType().Assembly);
  }

  public virtual bool Licensed => TxCommandLicenser.CreateContinuousMFGFromCurveLicense;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this._enabler;

  public virtual string Bitmap => "CreateContinuousMFGFromCurve.createcontinuousmfgfromcurve.bmp";

  public virtual string MediumBitmap
  {
    get => "CreateContinuousMFGFromCurve.CreateContinuousMfgsfromCurves_24px.png";
  }

  public virtual string LargeBitmap
  {
    get => "CreateContinuousMFGFromCurve.CreateContinuousMfgsfromCurves_32px.png";
  }

  public virtual ITxImage Image
  {
    get => (ITxImage) TxImageManager.GetImageByKey("CreateContinuousMfgFromCurve");
  }

  public virtual string Category
  {
    get => this._resourceManager.GetString("CREATE_CONTINUOUS_MFG_FROM_CURVE_CATEGORY");
  }

  public virtual string Description
  {
    get => this._resourceManager.GetString("CREATE_CONTINUOUS_MFG_FROM_CURVE_DESCRIPTION");
  }

  public virtual string[] AdvancedDescriptions => TxCallMessages.CollectMessages((ITxCommand) this);

  public virtual string Name
  {
    get => this._resourceManager.GetString("CREATE_CONTINUOUS_MFG_FROM_CURVE_NAME");
  }

  public virtual string Tooltip
  {
    get => this._resourceManager.GetString("CREATE_CONTINUOUS_MFG_FROM_CURVE_TOOLTIP");
  }

  public virtual void Execute(object cmdParams)
  {
    if (!this._enabler.Enable || this._createContinousMFGFromCurveForm != null)
      return;
    if (TxTcUtilities.IsTcAnyPlatform)
    {
      this._createContinousMFGFromCurveForm = (TxForm) new CCUiCMCCreateContinuousMFGFromCurveTCDlg();
      this.InitTCFormWithLastUsedObjects();
    }
    else
      this._createContinousMFGFromCurveForm = (TxForm) new CCUiCMCCreateContinuousMFGFromCurveDlg();
    ((Form) this._createContinousMFGFromCurveForm).FormClosed += new FormClosedEventHandler(this._createContinousMFGFromCurveForm_FormClosed);
    TxApplication.ApplicationEvents.Exiting += new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
    ((Control) this._createContinousMFGFromCurveForm).Show();
  }

  private void _createContinousMFGFromCurveForm_FormClosed(object sender, FormClosedEventArgs e)
  {
    if (TxTcUtilities.IsTcAnyPlatform)
    {
      CCUiCMCCreateContinuousMFGFromCurveTCDlg mfgFromCurveForm = this._createContinousMFGFromCurveForm as CCUiCMCCreateContinuousMFGFromCurveTCDlg;
      if (((Form) mfgFromCurveForm).DialogResult == DialogResult.Yes)
      {
        this._prevMfgContainer = mfgFromCurveForm.txebMfgContainer.Object;
        this._prevWeldOperation = mfgFromCurveForm.txebOperation.Object;
      }
    }
    this._createContinousMFGFromCurveForm = (TxForm) null;
    TxApplication.ApplicationEvents.Exiting -= new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
  }

  private void ApplicationEvents_Exiting(object sender, TxApplication_ExitingEventArgs args)
  {
    if (this._createContinousMFGFromCurveForm == null)
      return;
    ((Form) this._createContinousMFGFromCurveForm).Close();
  }

  private void InitTCFormWithLastUsedObjects()
  {
    CCUiCMCCreateContinuousMFGFromCurveTCDlg mfgFromCurveForm = this._createContinousMFGFromCurveForm as CCUiCMCCreateContinuousMFGFromCurveTCDlg;
    if (this._prevMfgContainer != null && this._prevMfgContainer.IsValid())
      mfgFromCurveForm.txebMfgContainer.Object = this._prevMfgContainer;
    if (this._prevWeldOperation == null || !this._prevWeldOperation.IsValid())
      return;
    mfgFromCurveForm.txebOperation.Object = this._prevWeldOperation;
  }
}
